import request from "@/utils/request";

const baseUrl = "teacherBase/";

/**
 * 获取所有教师信息
 * @param pagination
 * @param keyword
 * @returns {AxiosInstance}
 */
export function page(pagination, keyword) {
    return new request({
        url: `${baseUrl}list`,
        method: "GET",
        params: {...pagination, ...keyword}
    })
}

/**
 * 添加单个教师
 * @returns {AxiosInstance}
 * @param data
 */
export function addTeacherBase(data) {
    return new request({
        url: `${baseUrl}`,
        method: "POST",
        data: data
    })
}

/**
 * 修改单个教师
 * @returns {AxiosInstance}
 * @param data
 */
export function updateTeacherBase(data) {
    return new request({
        url: `${baseUrl}`,
        method: "PUT",
        data: data
    })
}

/**
 * 删除单个教师
 * @returns {AxiosInstance}
 * @param id
 */
export function deleteTeacherBase(id) {
    return new request({
        url: `${baseUrl}?id=${id}`,
        method: "DELETE",
    })
}

/**
 * 删除多个教师
 * @returns {AxiosInstance}
 * @param ids
 */
export function deleteMultipleTeacherBase(ids) {
    let filterIds = "?";
    ids.forEach(item => filterIds += `ids=${item}&`);
    filterIds = filterIds.substr(0, filterIds.length - 1);
    return new request({
        url: `${baseUrl}multiple${filterIds}`,
        method: "DELETE",
    })
}

// /**
//  * 导出信息
//  * @param pagination
//  * @param keyword
//  * @returns {AxiosInstance}
//  */
// export function exportExcel(keyword) {
//     return new request({
//         url: `${baseUrl}export`,
//         method: "GET",
//         data: keyword,
//         responseType: 'blob'
//     })
// }

/**
 * 导出信息
 * @param pagination
 * @param keyword
 * @returns {AxiosInstance}
 */
export function exportExcel(ids,keyword) {
    let filterIds = "?";
    ids.forEach(item => filterIds += `ids=${item}&`);
    filterIds = filterIds.substr(0, filterIds.length - 1);
    return new request({
        url: `${baseUrl}export${filterIds}`,
        method: "GET",
        params:{...keyword,...ids},
        responseType: 'blob'
    })
}

/**
 * 教资力量统计
 * @returns {AxiosInstance}
 */
export function chartDegree() {
    return new request({
        url: `${baseUrl}chart/degree`,
        method: "GET"
    })
}
